/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function() 
{
    $(window).resize(
        function()
        {
            $('div.popUpBackground').css("height",$(document).height());
            $('div.popUpBackground').css("width",$(document).width());
            $('.addMessagePopUp').css("top", ($(window).height() - $('.addMessagePopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
            $('.addMessagePopUp').css("left", ($(window).width() - $('.addMessagePopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
        }
    );
    $('.btnMessage').mouseover
    (
        function () 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "#444444");
            $(this).css("color", "#4f0000")
        }
    );
    $('.btnMessage').mouseleave
    (
        function () 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "#000000");
            $(this).css("color", "#ffffff")
        }
    );
    $('div.closePopUp').hover
    (
        function () 
        {
            $(this).css('cursor','pointer');
        }
    );
    $('div.closePopUp').click
    (
        function () 
        {
            $('div.popUpBackground').css("z-index","-1");
            $('div.popUpBackground').fadeOut("slow");
            $('div.addMessagePopUp').fadeOut("slow");
        }
    );
    $('#btnNouvMessage').click(
        function()
        {
            if($('.popUpMessage').attr('value').length > 0)
            {
                $(this).parent().submit();
            }
            if($('.popUpMessage').attr('value').length == 0)
            {
                $('.popUpMessage').addClass('invalide');
            }
            else
            {
                $('.popUpMessage').removeClass('invalide');
            }
        }
    );
    $('div.btnMessage').click
    (
        function () 
        {
            if($(this).attr("id")=="add"){
                $('div.popUpBackground').css("z-index","2");
                $('div.popUpBackground').css("height",$(document).height());
                $('div.popUpBackground').css("width",$(document).width());
                $('div.popUpBackground').fadeIn("slow");
                $('div.addMessagePopUp').fadeIn("slow");
                $('div.addMessagePopUp').css("top", ($(window).height() - $('div.addMessagePopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
                $('div.addMessagePopUp').css("left", ($(window).width() - $('div.addMessagePopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
            }
            else if($(this).attr("id")=="delete"){
                var nbrSelected = 0;
                $('.chkDiscussion').each(
                    function()
                    {
                        if(this.checked)
                        {
                            ++nbrSelected;
                        }
                    }
                );
                if(nbrSelected == 0)
                {                    
                }
                else
                {
                    confirmeSupp = false;
                    confirmeSupp = confirm($('#deleteDialog').html());
                    if(confirmeSupp)
                    {
                        $(".messages").children("form").submit();
                    }
                }
            }
        }
    );
    $('div.popUpBackground').click
    (
        function ()
        {
            $('div.popUpBackground').css("z-index","-1");
            $('div.popUpBackground').fadeOut("slow");
            $('div.addMessagePopUp').fadeOut("slow");
        }
    );
    $('#navigation a').mouseover
    (
        function()
        {
            if($(this).attr("id")=="hover"){
                $(this).css("color","#4f0000");
                $('#hoverRoot').css("height",$(this).height());
                $('#hoverRoot').css("width",$(this).width());
                $('#hoverRoot').css("top",$(this).position().top);
                $('#hoverRoot').css("left",$(this).position().left);
                $('#hoverRoot').css("z-index","3");
                $('#hoverRoot').fadeIn("fast");
                $('#hoverBg').css("height",$(document).height());
                $('#hoverBg').css("width",$(document).width());
                $('#hoverBg').fadeIn("fast");
                $('#hoverBg').css("z-index","2");
            }
        }
    );
    $('#hoverBg').mouseover(
        function()
        {
            $('#hover').css("color","#ffffff");
            $('.hoverMenu').css("display","none");
            $('#hoverRoot').css("display","none");
            $('#hoverBg').css("z-index","-1");
            $('#hoverRoot').css("z-index","-1");
            $('#hoverBg').css("display","none");
        }
    );
    $('#hoverRoot').click(
        function()
        {
            $(this).children('form').submit();
        }
    );
});

